package DMSXL._2024.BinaryTrees;

public class CreateTree {
    public static void main(String[] args) {

    }
    public static TreeNode createBinaryTree(Integer[] array, int index) {
        TreeNode root = null;
        if (index < array.length) {
            Integer value = array[index];
            if (value != null) {
                root = new TreeNode(value);
                root.left = createBinaryTree(array, 2 * index + 1);  // 左子节点
                root.right = createBinaryTree(array, 2 * index + 2); // 右子节点
            }
        }
        return root;
    }
}
